#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
string multiply(string num1, string num2) {

    int end1 = num1.size();
    int end2 = num2.size();
    int end3 = end1 + end2;
    int i = 0; int next = 0;
    string tmp;
    while ((end1 > 0 || end2 > 0) && end3-1 > i)
    {
        int a = num1.size();
        int b = num2.size();
        int n; int end = next;
        next = 0;
        while (a > 0 || b > 0)
        {
            if (end3 - a - b == i)
            {
                int n1 = (a - 1) >= 0 ? num1[a - 1] - '0' : 0;
                int n2 = (b - 1) >= 0 ? num2[b - 1] - '0' : 0;
                n = n1 * n2;
                next += n / 10;
                end += n % 10;
            }
            a > b ? --a : --b;
        }
        if (end >= 10)
        {
            next += end / 10;
            end %= 10;
        }
        tmp += end + '0';
        end1>end2?--end1:--end2; 
        ++i; 
    }
    reverse(tmp.begin(), tmp.end());
    return tmp;
}
string reverseWords(string s) {
    size_t pos = s.find(' ');
    int i = 0;
    while (pos != -1)
    {
        reverse(&s[i], &s[pos]);
        i = pos+1;
        pos = s.find(' ', i);
    }
    reverse(&s[i], &s[s.size()]);
    return s;
}
string reverseStr(string s, int k) {
    int i = 0; int n = s.size();
    int d = 0;
    if (n < k)
    {
        reverse(s.begin(), s.end());
        return s;
    }
    if (n < 2 * k && n >= k)
    {
        reverse(&s[0], &s[k]);
        return s;
    }

    while (d < n&&d+k<=n)
    {
        int a = d % (2 * k);
        
        if (a == 0)
        {
            reverse(&s[i], &s[k + i]);
            i += 2 * k;
        }
        d++;
    }
    n %= 2 * k;
    if (n < k)
    {
        reverse(&s[i], &s[s.size()]);
    }
    if (n < 2 * k && n >= k)
    {
        reverse(&s[i], &s[k + i]);
    }
    return s;
}
int main()
{
	string s1 = "abcdefg" ;
    int pos = s1.find(' ');

    string s2 = "11";
    reverseStr(s1,3);
    cout << s1;
}